package test01;

import java.sql.*;

public class Test {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //获取连接
        Class.forName("com.mysql.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/ppml?useSSL=false&serverTimezone=UTC";
        String username = "root";
        String password = "123456";
        Connection connection = DriverManager.getConnection(url,username,password);
        //创建会话
        Statement statement = connection.createStatement();
        //发送sql
        ResultSet resultSet = statement.executeQuery("select * from tb_user");
//        ResultSet resultSet = statement.getResultSet();
//        System.out.println(resultSet);
        System.out.println(resultSet);

        while (resultSet.next()) {
            // 获取列的值，假设我们知道列的名字
            int id = resultSet.getInt("id"); // 假设有一个名为id的列
            String userName = resultSet.getString("userName"); // 假设有一个名为username的列
            // ... 获取其他列的值

            // 打印结果或者进行其他处理
            System.out.println("ID: " + id + ", userName: " + userName);
        }

        statement.close();
        connection.close();

    }
}
